<?php
	/* Program: functions.inc 
	* Function addNewType
 	*/
	
function addNewType($groceryType,$typeDescription,$cxn)
{
	/* Check whether new category is in PetType table.
		If it is not in table, add it to table. */
	$query = "SELECT groceryType FROM GroceryType
							WHERE groceryType='$groceryType'";
	$result = mysqli_query($cxn,$query) or
		die ("Couldn't execute select query");
	
	$ntype = mysqli_num_rows($result);
	
	if ($ntype < 1) // if new type is not in table
	{
		$groceryType = ucfirst(strip_tags(trim($groceryType)));
		$typeDescription =
			ucfirst(strip_tags(trim($typeDescription)));
		$groceryType = mysqli_real_escape_string($cxn,$groceryType);
		$typeDescription =
			mysqli_real_escape_string($cxn,$typeDescription);
			
		$query="INSERT INTO groceryType (groceryType, typeDescription)
				VALUES ('$groceryType', '$typeDescription')";
		$result = mysqli_query($cxn,$query)
					or die("Couldn't execute insert query");
	}
	return;
}
?>